package ejT5;

import java.util.Scanner;

public class Ej04 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		System.out.print("Introduce n: ");
		int n = sc.nextInt();

		int crapuloN = crapulo(n);
		System.out.println("El crapulo de "+n+" es " + crapuloN);

	}

	private static int crapulo(int n) {

		int acc = 0;
		while (n > 0) {
			acc += n % 10;
			n /= 10;
		}

		if (longitud(acc) > 1) {
			return crapulo(acc);
		} else {
			return acc;
		}

	}

	private static int longitud(int numero) {
		int sol = 0;
		while (numero > 0) {
			numero /= 10;
			sol++;
		}

		return sol;
	}

}
